package com.sfh.cpc.note;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.google.gson.Gson;
import com.jaeger.library.StatusBarUtil;
import com.sfh.cpc.R;
import com.sfh.cpc.com.entity.EMessage;
import com.sfh.cpc.com.req.ReqMessage;
import com.sfh.cpc.note.model.NoteAddMsg;
import com.sfh.lib.mvvm.annotation.LiveDataMatch;
import com.sfh.lib.ui.AbstractLifecycleActivity;


/**
 * 功能描述:
 *
 * @author
 * @date 2018/5/2
 */
public class NoteAddMessageActivity extends AbstractLifecycleActivity<NoteAddMsg> {

    public static void startUI(Activity context, Long noteId, long massId) {
        Intent intent = new Intent(context, NoteAddMessageActivity.class);
        intent.putExtra("noteId", noteId);
        intent.putExtra("massId", massId);
        context.startActivityForResult(intent,1000);
    }

    EditText etContent;

    long massId;
    long noteId;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.note_add_message_activity);
        StatusBarUtil.setColor(this, Color.WHITE,0);
        init();
    }

    private void init() {
        etContent = findViewById(R.id.etContent);
        noteId = getIntent().getLongExtra("noteId", 0);
        massId = getIntent().getLongExtra("massId", 0);
    }

    public void onViewCilcked(View view) {

        ReqMessage req = new ReqMessage();
        req.setContent(etContent.getText().toString());
        req.setNoteId(noteId);
        req.setMassId(massId);
        getViewModel().addMessage(req);

    }

    @LiveDataMatch
    public void onSuccess() {
        EMessage message =EMessage.createTemp(etContent.getText().toString());
        Intent data = new Intent();
        data.putExtra("DATA",new Gson().toJson(message));
        setResult(RESULT_OK,data);
        finish();
    }
}
